{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d7100716-2c0a-478e-a4fc-b2fe4cd2c3c0",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-09T14:45:05.396822Z",
     "iopub.status.busy": "2022-05-09T14:45:05.395822Z",
     "iopub.status.idle": "2022-05-09T14:45:05.415254Z",
     "shell.execute_reply": "2022-05-09T14:45:05.414256Z",
     "shell.execute_reply.started": "2022-05-09T14:45:05.395822Z"
    },
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## 数据回放测试，用于查找问题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c94d6124-6426-4e54-a1e9-c010115d5452",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "from chanlun.backtesting.backtest_klines import BackTestKlines\n",
    "from chanlun import kcharts\n",
    "from chanlun.cl_utils import query_cl_chart_config"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "920c7e5c-96bd-4aab-83a6-3e1a4be3a387",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# 回放的数据配置\n",
    "market = 'currency'\n",
    "code = 'ETH/USDT'\n",
    "start_date = '2023-02-02 14:30:00'\n",
    "end_date = '2023-02-02 15:00:00'\n",
    "frequencys = ['5m']\n",
    "\n",
    "cl_config = query_cl_chart_config(market, code)\n",
    "\n",
    "bk = BackTestKlines(market, start_date, end_date, frequencys, cl_config)\n",
    "bk.init(code, frequencys[-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c95d98cb-bdb1-4ff4-a65e-12dbaf5b2985",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# 依次执行此单元格，检查缠论计算结果\n",
    "bk.next()\n",
    "cd = bk.get_cl_data(code, frequencys[0])\n",
    "kcharts.render_charts(code, cd, config=cl_config)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "51be9b43-1525-4e38-8ee3-014ad990ff25",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "cd2 = bk.get_cl_data(code, frequencys[0])\n",
    "kcharts.render_charts(code, cd2, config=cl_config)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0985e297-a61e-4255-bb3a-8c85564c0ed4",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "print(cd.get_bi_zss()[-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0632f8b4-0bfc-4ce9-8017-9cd402728292",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "bk.now_date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c1a6ede5-c34b-411a-b7f7-48252cb6a496",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "print(cd.get_xds()[-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c42814c3-40dc-4b91-83f2-f11e99557501",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "tags": []
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8fe94ca7-e70c-49d4-bc3c-3143dc5e6105",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "tags": []
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "326fa8c6-a1a4-40ab-aae7-74f031ade93c",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
